<?php
/**
 * Ponta先着ポイントプレゼントキャンペーンモデルクラス<br />
 *
 * @package apamanshop
 * @author H.Imamura
 * @copyright (c) 2014 SystemSoft Corp. All rights reserved
 */
class Inquiry_Model_Ponta201402 extends Inquiry_Model_Apibase
{
	/**
	 * 応募ログカウント
	 *
	 * @return int 応募ログ総数
	 */
	public function countEntryLog($params=array(), $db="")
	{
		$count = 0;
		$db_params = array();
		$sqlWhere = array();
		$sql  = "SELECT count(C14_PONTA_ID) as CNT";
		$sql .= "  FROM CAMPAIGN_USER.C201401_PONTA_ENTRY_LOG";
		if (isset($params['fromDate'])) {
			// 開始日
			$sqlWhere[] = "C14_TOUROKUBI >= to_date(:fromDate, 'yyyyMMdd')";
			$db_params['fromDate'] = $params['fromDate'];
		}
		if (isset($params['pontaId'])) {
			// pontaID
			$sqlWhere[] = "C14_PONTA_ID = :pontaId";
			$db_params['pontaId'] = $params['pontaId'];
		}
		if (count($sqlWhere) > 0) {
			$sql .= " WHERE ";
			$sql .= implode(' AND ', $sqlWhere);
		}
		$data = $this->dbGetData($sql, $db_params, $db);
		if (isset($data['CNT']) && is_numeric($data['CNT'])) {
			$count = intVal($data['CNT']);
		}
		return $count;
	}

	/**
	 * 応募ログ登録
	 *
	 * @return boolean
	 */
	public function insertEntryLog($params, $db)
	{
		$db_params = array();
		
		$sql  = "INSERT INTO CAMPAIGN_USER.C201401_PONTA_ENTRY_LOG (";
		$sql .= "  C14_PONTA_ID";
		$sql .= " ,C14_TOIAWASE_ID";
		$sql .= " ,C14_TOUROKUBI";
		$sql .= ") VALUES (";
		$sql .= "  :pontaId";
		$sql .= " ,:toiawaseId";
		$sql .= " ,sysdate";
		$sql .= ")";
		
		$db_params['pontaId']    = $params['pontaId'];
		$db_params['toiawaseId'] = $params['toiawaseId'];
		
		$count = $this->dbExecQuery($sql, $db_params, $db);
		if ($count > 0) {
			return true;
		} else {
			return false;
		}
	}

}
?>
